package 菜单项;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextArea;
import javax.swing.JTextField;

public class Find extends JFrame implements ActionListener {
	JButton button1;
	JTextField textField1, replacefield;
	ActionListener actionlistener;
	JTextArea showText;

	Find() {

		setLayout(null);
		setBounds(100, 150, 300, 300);
		init();

		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setVisible(true);
	}

	public void setShowText(JTextArea text) {
		showText = text;
	}

	void init() {
		// 两个框

		textField1 = new JTextField(null, 10);
		textField1.setBounds(57, 79, 100, 27);
		add(textField1);

		replacefield = new JTextField(null, 10);
		replacefield.setBounds(57, 134, 100, 27);
		add(replacefield);
		button1 = new JButton("替换");
		button1.setBounds(200, 79, 68, 27);
		add(button1);

		button1.addActionListener(this);

	}

	public void actionPerformed(ActionEvent e) {

		if (e.getSource() == button1) {

			String str1 = textField1.getText();
			String str2 = replacefield.getText();
			String str3 = showText.getText().replace(str1, str2);
			replacefield.setText(str3);
			showText.setText(str3);
		}
	}
}
